package com.zry.retorfit.config;

import android.app.Application;
import android.os.Environment;
import com.zry.retorfit.persistentcookiejar.ClearableCookieJar;
import com.zry.retorfit.persistentcookiejar.PersistentCookieJar;
import com.zry.retorfit.persistentcookiejar.cache.SetCookieCache;
import com.zry.retorfit.persistentcookiejar.persistence.SharedPrefsCookiePersistor;
import java.io.File;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;


public class RetrofitApplication extends Application {
    /**
     * 线程池
     */
    private ExecutorService cachedThreadPool = new ThreadPoolExecutor(8, 8, 0L,
            TimeUnit.MILLISECONDS, new LinkedBlockingQueue<>(100000),
            new ThreadPoolExecutor.CallerRunsPolicy());

    /**
     * 图片保存路径
     */
    public String photoSavePath = Environment.getExternalStorageDirectory().getAbsolutePath() + "/kangyineng/image/";
    /**
     * 文件保存路径
     */
    public String apkSavePath = Environment.getExternalStorageDirectory().getAbsolutePath() + "/kangyineng/";

    public ClearableCookieJar cookieJar;


    private static RetrofitApplication instance;

    public static RetrofitApplication getInstance() {
        return instance;
    }

    @Override
    public void onCreate() {
        super.onCreate();
        instance = this;
        cookieJar = new PersistentCookieJar(new SetCookieCache(), new SharedPrefsCookiePersistor(instance));

        File photoFile = new File(photoSavePath);
        if (!photoFile.exists()) {
            photoFile.mkdirs();
        }

    }

}
